﻿using System;
using System.Web.UI;
using AjaxPro;
using Common;
using JinJiang.BookingEngine.Services;

namespace JinJiang.BookingEngine.Web.en.usercontrol
{
    public partial class UserLogin : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var display = "none";
            Utility.RegisterTypeForAjax(typeof (UserLogin), Page);
            //this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "filed_kang_mobile", "<script language=\"javascript\" type=\"text/javascript\">getContrl(userLogin.pnlGuestInfo).style.display=\"none\";</script>");
            if (!string.IsNullOrEmpty(LoginInfo.LoginName))
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "filed_kang_user", "<script language=\"javascript\" type=\"text/javascript\">JinJiang.BookingEngine.Web.en.usercontrol.UserLogin.GetUserInfo(\"" + LoginInfo.LoginName + "\", \"" + LoginInfo.Password + "\",Scores, GetUserInfoResult);</script>");
            }
        }

        [AjaxMethod]
        public string GetUserInfo(string cardnum, string pwd, decimal scores)
        {
            MemberInfo member;
            MemberService memberService = new MemberService();
            if (memberService.UserLogin(cardnum, pwd, out member))
            {
                if(member != null)
                {
                    return "IsLogin=true;userinfo=['" + member.FirstName + "','" + member.LastName + "','" + member.UserId + "','" + member.CardLevel + "','" + member.Point + "','" + member.Email + "','" + member.Mobile + "','" + member.Address + "']";
                }
            }
            return "IsLogin=false;userinfo=['','','','','','','','']";
        }
    }
}